package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.PersonDto;
import com.yxy.dto.PersonListDto;
import com.yxy.service.PersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author yuxiaoyang
 * 人员管理
 */
@RestController
@Slf4j
@RequestMapping("/person")
public class PersonController {

  @Autowired
  private PersonService functionService;

  // 获取列表
  @Pagingable
  @PostMapping("/list")
  public RestResponse getList(@RequestBody PersonListDto inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(functionService.getList(inputDto));
    return restResponse;
  }

  //创建 或 修改白名单
  @PostMapping("/createOrUpdate")
  public RestResponse createOrUpdate(@RequestBody @Valid PersonDto inputDto) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(functionService.createOrUpdate(inputDto));
    return restResponse;
  }

  //删除白名单
  @DeleteMapping("/{id}")
  public RestResponse deletePerson(@PathVariable("id") long id) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    functionService.deletePerson(id);
    return restResponse;
  }
}
